Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes an issue where asking a mock for values in a concurrent way causes a crash in the VerifyContainer #69

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kevmalek
Copy link

@kevmalek kevmalek commented Nov 22, 2024

If we try to access a mocked value when another thread is accessing the mock at the same time, we can get a crash.

We're seeing this consistently when we're running Xcode tests repeatedly.

We're now appending to the arrays in VerifyContainer and InOrderContainer in a thread-safe manner.

Copy link

@NineToeNerd NineToeNerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need the same fix in the InOrderContainer

isVerified.append(false)

InOrderContainer.append(mock: mock, call: call, function: function)
queue.sync { [weak self] in
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda wierd. We call closure synchronous on the queue, but capture self in a weak manner.
Just use unowned reference

@@ -11,15 +11,18 @@ public class VerifyContainer: CallContainer {
var calls: [Any] = []
var functions: [String] = []
var isVerified: [Bool] = []

private let queue = DispatchQueue(label: "VerifyContainerQueue")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix indentation, please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants